package com.fh.controller;

import java.io.File;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import com.fh.util.Upload;

@Controller
@RequestMapping(value = "/UploadController")
public class UploadController {
	@RequestMapping("/upload")
	public String login(@RequestParam(value = "file", required = false) MultipartFile file, HttpServletRequest request, ModelMap model) {
	        String path = request.getSession().getServletContext().getRealPath("upload");  
	        String fileName = file.getOriginalFilename(); 
	        File targetFile = new File(path, fileName);  
	        if(!targetFile.exists()){  
	            targetFile.mkdirs();  
	        }  
	        //保存  
	        try {  
	            file.transferTo(targetFile);  
	        } catch (Exception e) {  
	            e.printStackTrace();  
	        }  
	     model.addAttribute("fileUrl", request.getContextPath()+"/upload/"+fileName);  
		return "login";
	}
	
	
	
	@RequestMapping("/uploads")
	public String logins(@RequestParam(value = "file", required = false) MultipartFile[] files, HttpServletRequest request, ModelMap model) {

		Upload upload=new Upload(request);
		 
		upload.uploads(files);
		return "login";
	}
	

	
	
	
	
	
	
}
